import React from 'react';
import { Button, Tag, Tooltip, Space } from 'antd';

// 常量定义
const patentTypes = ["发明", "实用新型", "外观设计", "PCT"];
const statusOptions = [
  "有权",
  "无权-届满",
  "无权-未缴年费",
  "无权-放弃专利权（重复授权）",
  "无权-视为撤回",
  "无权-驳回",
  "撤案",
  "代理处理中",
  "申请失败",
  "审中-初审合格",
  "审中-实审",
  "审中 - 一审",
  "审中-N审",
  "无效",
];
const departmentOptions = ["智能硬件部", "能源系统部", "研发部", "知识产权部"];
const strategyTypes = ["防御型", "攻击型"];

/**
 * 生成专利管理表格的列配置
 * @param {Object} handlers - 包含表格操作的处理函数
 * @returns {Array} 列配置数组
 */
export const getColumns = ({ onEdit, onDelete, onChangePatentee }) => [
  {
    title: "序号",
    dataIndex: "id",
    key: "id",
    width: 80,
    fixed: "left",
    sorter: (a, b) => a.id - b.id,
    defaultSortOrder: "ascend",
    ellipsis: true,
  },
  {
    title: "我司案号",
    dataIndex: "case_number",
    key: "case_number",
    width: 120,
    fixed: "left",
    ellipsis: true,
  },
  {
    title: "专利名称",
    dataIndex: "patent_name",
    key: "patent_name",
    width: 200,
    fixed: "left",
    ellipsis: true,
  },
  {
    title: "专利申请号",
    dataIndex: "application_number",
    key: "application_number",
    width: 150,
    ellipsis: true,
  },
  {
    title: "专利类型",
    dataIndex: "patent_type",
    key: "patent_type",
    width: 120,
    filters: patentTypes.map((type) => ({ text: type, value: type })),
    onFilter: (value, record) => record.patent_type === value,
    ellipsis: true,
  },
  {
    title: "专利状态",
    dataIndex: "patent_status",
    key: "patent_status",
    width: 150,
    filters: statusOptions.map((status) => ({ text: status, value: status })),
    onFilter: (value, record) => record.patent_status === value,
    render: (text) => {
      let color = "blue";
      if (text && text.includes("无权")) {
        color = "red";
      } else if (text === "有权") {
        color = "green";
      } else if (text && text.includes("审中")) {
        color = "orange";
      }
      return text ? <Tag color={color}>{text}</Tag> : null;
    },
    ellipsis: true,
  },
  {
    title: "专利权人",
    dataIndex: "patentee",
    key: "patentee",
    width: 140,
    ellipsis: true,
  },
  {
    title: "变更后专利权人",
    dataIndex: "changed_patentee",
    key: "changed_patentee",
    width: 140,
    ellipsis: true,
  },
  {
    title: "变更手续合格日期",
    dataIndex: "change_procedure_date",
    key: "change_procedure_date",
    width: 150,
    ellipsis: true,
  },
  {
    title: "发明人",
    dataIndex: "inventors",
    key: "inventors",
    width: 150,
    ellipsis: true,
    render: (text) => (
      <Tooltip title={text}>
        <span>{text}</span>
      </Tooltip>
    ),
  },
  {
    title: "第一发明人",
    dataIndex: "first_inventor",
    key: "first_inventor",
    width: 120,
    ellipsis: true,
  },
  {
    title: "来源部门",
    dataIndex: "department",
    key: "department",
    width: 120,
    filters: departmentOptions.map((dept) => ({ text: dept, value: dept })),
    onFilter: (value, record) => record.department === value,
    ellipsis: true,
  },
  {
    title: "关联产品",
    dataIndex: "related_product",
    key: "related_product",
    width: 140,
    ellipsis: true,
  },
  {
    title: "关联立项/课题",
    dataIndex: "related_project",
    key: "related_project",
    width: 140,
    ellipsis: true,
  },
  {
    title: "防御型/攻击型",
    dataIndex: "strategy_type",
    key: "strategy_type",
    width: 120,
    filters: strategyTypes.map((type) => ({ text: type, value: type })),
    onFilter: (value, record) => record.strategy_type === value,
    ellipsis: true,
  },
  {
    title: "是否为核心",
    dataIndex: "is_core",
    key: "is_core",
    width: 100,
    render: (text) =>
      text ? <Tag color="green">是</Tag> : <Tag color="default">否</Tag>,
    filters: [
      { text: "是", value: true },
      { text: "否", value: false },
    ],
    onFilter: (value, record) => record.is_core === value,
    ellipsis: true,
  },
  {
    title: "核心分数",
    dataIndex: "core_score",
    key: "core_score",
    width: 100,
    sorter: (a, b) => a.core_score - b.core_score,
    ellipsis: true,
  },
  {
    title: "技术交底书收集时间",
    dataIndex: "disclosure_collection_date",
    key: "disclosure_collection_date",
    width: 150,
    ellipsis: true,
  },
  {
    title: "原始交底书名称",
    dataIndex: "original_disclosure_name",
    key: "original_disclosure_name",
    width: 180,
    ellipsis: true,
    render: (text) => (
      <Tooltip title={text}>
        <span>{text}</span>
      </Tooltip>
    ),
  },
  {
    title: "受理发文",
    dataIndex: "acceptance_notice_date",
    key: "acceptance_notice_date",
    width: 120,
    ellipsis: true,
  },
  {
    title: "授权发文",
    dataIndex: "grant_notice_date",
    key: "grant_notice_date",
    width: 120,
    ellipsis: true,
  },
  {
    title: "下证发文",
    dataIndex: "certificate_issue_date",
    key: "certificate_issue_date",
    width: 120,
    ellipsis: true,
  },
  {
    title: "无效日期",
    dataIndex: "invalidation_date",
    key: "invalidation_date",
    width: 120,
    ellipsis: true,
  },
  {
    title: "代理机构处理时间",
    dataIndex: "agency_process_date",
    key: "agency_process_date",
    width: 150,
    ellipsis: true,
  },
  {
    title: "国知局处理时间",
    dataIndex: "cnipa_process_date",
    key: "cnipa_process_date",
    width: 150,
    ellipsis: true,
  },
  {
    title: "是否走快审通道",
    dataIndex: "fast_track",
    key: "fast_track",
    width: 130,
    render: (text) =>
      text ? <Tag color="green">是</Tag> : <Tag color="default">否</Tag>,
    filters: [
      { text: "是", value: true },
      { text: "否", value: false },
    ],
    onFilter: (value, record) => record.fast_track === value,
    ellipsis: true,
  },
  {
    title: "代理机构",
    dataIndex: "agency",
    key: "agency",
    width: 140,
    ellipsis: true,
  },
  {
    title: "负责人",
    dataIndex: "manager",
    key: "manager",
    width: 100,
    ellipsis: true,
  },
  {
    title: "代理案号",
    dataIndex: "agency_case_number",
    key: "agency_case_number",
    width: 120,
    ellipsis: true,
  },
  {
    title: "（发展部）关联课题/项目",
    dataIndex: "related_development_project",
    key: "related_development_project",
    width: 180,
    ellipsis: true,
  },
  {
    title: "特殊事项备注",
    dataIndex: "special_notes",
    key: "special_notes",
    width: 200,
    ellipsis: true,
    render: (text) => (
      <Tooltip title={text}>
        <span>{text}</span>
      </Tooltip>
    ),
  },
  {
    title: "操作",
    key: "action",
    fixed: "right",
    width: 180,
    render: (_, record) => (
      <Space>
        <Button
          type="text"
          style={{ color: "#1677ff" }}
          onClick={() => onEdit(record)}
        >
          编辑
        </Button>
        <Button type="text" danger onClick={() => onDelete(record)}>
          删除
        </Button>
        <Button
          type="text"
          style={{ color: "#1677ff" }}
          onClick={() => onChangePatentee(record)}
        >
          变更专利权人
        </Button>
      </Space>
    ),
  },
];

// 导出常量供其他文件使用
export { patentTypes, statusOptions, departmentOptions, strategyTypes };